< previous page page_607 next page >

Page 607
Creating UPDATE Queries with the UPDATE_SET Statement
The UPDATE_SET statement enables you to update a large amount of data in one or more tables very quickly with very little coding. You use the UPDATE_SET statement to modify data already on file in a data table. The advantage of the UPDATE_SET statement is that you can use a single statement to modify multiple rows in the table.
For example, assume that you have a table of 500 employees. You are told by the Human Resources department that all employees are to be given a 17.5 percent increase in their pay starting immediately (wouldn't it be nice?). You could write a Visual Basic program that opens the table, reads each record, computes the new salary, stores the updated record, and then goes back to read the next record. Your code would look something like the pseudocode sample in Listing 15.5.
Note.gif
Listing 15.5 is not a real Visual Basic program; it is just a set of statements that read like program code. Such pseudocode is often used by programmers to plan out programs without having to deal with the details of a particular programming language. Another benefit of using pseudocode to plan programs is that people do not need to know a particular programming language to be able to understand the example.

Type.gifListing 15.5. Sample code for record-oriented updates.
OPEN EmpDatabase
OPEN EmpTable
DO UNTIL END-OF-FILE (EmpTable)
   READ EmpTable RECORD
   EmpTable.EmpSalary = EmpTable.EmpSalary * 1.175
   WRITE EmpTable RECORD
END DO
CLOSE EmpTable
CLOSE EmpDatabase
This is a relatively simple process, butdepending on the size of the data table and the speed of your workstation or the database serverthis kind of table update could take quite a bit of time. You can use the SQL UPDATE statement to perform the same task.
OPEN database
UPDATE EmpTable SET EmpSalary = EmpSalary * 1.175
CLOSE database

 
< previous page page_607 next page >

If you like this book, buy it!